#!/bin/bash
#IScript

#_framework_ROOT: 脚本的根目录，就是example.sh所在的地方
readonly _this_ROOT="$(cd "$(dirname "${BASH_SOURCE:-$0}")" || exit 2;pwd)";
#shellcheck disable=SC1090
source "$_this_ROOT/framework/frameworks.sh";

#脚本

#一般输出
_Logger_Log Info "Info!";

_Logger_Log Warn "Warn!";
_Logger_Log Warning "Warning!";

_Logger_Log Error "Error!";
_Logger_Log Erro "Erro!";
_Logger_Log Err "Err!";

_Logger_Log Ok "Ok!";

#通过管道进行Logger输出。用法：<命令> | _Logger_LogFromPipe [日志等级]
echo "Log From Pipe!" | _Logger_LogFromPipe

_Logger_Log;

#region _framework_ThrowErrorAndExit
_Logger_Log Info "_framework_ThrowErrorAndExit"
_framework_ThrowErrorAndExit&
pid=$!;
wait $pid;

_Logger_Log Info "_framework_ThrowErrorAndExit 1"
_framework_ThrowErrorAndExit 1&
pid=$!;
wait $pid;

_Logger_Log Info "_framework_ThrowErrorAndExit Network"
_framework_ThrowErrorAndExit Network&
pid=$!;
wait $pid;

_Logger_Log Info "_framework_ThrowErrorAndExit SwitchDir"
_framework_ThrowErrorAndExit SwitchDir&
pid=$!;
wait $pid;

_Logger_Log Info "_framework_ThrowErrorAndExit InvaildValue"
_framework_ThrowErrorAndExit InvaildValue&
pid=$!;
wait $pid;

_Logger_Log Info "_framework_ThrowErrorAndExit Debug"
_framework_ThrowErrorAndExit Debug&
pid=$!;
wait $pid;
#endregion _framework_ThrowErrorAndExit

#region SimpleCM
_SimpleCM_SetValue "foo" "bar";
_SimpleCM_GetValue "foo" | _Logger_LogFromPipe Info false "获得的值为";

echo "${_SimpleCM_File:?}" > /dev/null;
rm "$_SimpleCM_File";
_SimpleCM_InitConfigFile;
_SimpleCM_SetValue "foo" "bar";
_Logger_LogFromPipe Info true < "$_SimpleCM_File"

rm "$_SimpleCM_File";
_SimpleCM_ChangeTargetFile "NewTarget";
_SimpleCM_SetValue "foo" "bar";
_SimpleCM_GetValue "foo" | _Logger_LogFromPipe Info false "获得的值为";
_Logger_LogFromPipe Info true < "$_SimpleCM_File"
